﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Shell;
using System.Diagnostics;
using EnvDTE;


namespace devtm.Editor.TypeSelector.ParsingSolution
{

    public class Solution : SolutionItem
    {

        private EnvDTE.Solution solution;
        EnvDTE.DTE dte;
        public Solution () : base() 
        {
            dte = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE));
            solution = dte.Solution;
        }

        public string Name
        {
            get { return FindProperty("Name").Value; }
            set { FindProperty("Name").Value = value; }
        }

        public EnvDTE.DTE GetDTE { get { return dte; } }
       

        public override IEnumerable<T> GetItem<T>()
        {

            EnvDTE.DTE dte = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE));

            foreach (EnvDTE.Project project in dte.Solution.Projects)
            {

                SolutionItem fld = null;

                if (project.Kind == "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}" || project.Kind == "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}")
                    fld = new FolderSolution(project);

                else if (project.Kind == "{EA6618E8-6E24-4528-94BE-6889FE16485C}")
                    fld = new VirtualFolder(project);  
                
                else                
                    fld = new Project(project);

                if (fld is T)
                    yield return fld as T;

                foreach (T item in fld.GetItem<T>())                
                    yield return item;
                
            }

        }



        protected override void BuildProperties()
        {
            _properties = new Dictionary<string, Property>();

            foreach (Property item in solution.Properties)
                _properties.Add(item.Name, item);

        }

    }
}
